import 'package:flutter/material.dart';

///简单的对text封装
class DefaultText extends StatelessWidget {
  const DefaultText(this.text,
      {Key? key, this.color, this.backgroundColor, this.fontSize, this.fontWeight, this.fontFamily})
      : super(key: key);
  final String text;
  final Color? color;
  final Color? backgroundColor;
  final double? fontSize;
  final double? fontWeight;
  final FontFamily? fontFamily;

  @override
  Widget build(BuildContext context) {
    return Text(text,
        style: TextStyle(
            color: color ?? const Color(0xff666666),
            fontSize: fontSize ?? 14,
            backgroundColor: backgroundColor,
            decoration: TextDecoration.none,
            fontFamily: _getFontFamily(fontFamily),
            fontWeight: fontWeight == 1 ? FontWeight.w400 : FontWeight.w600));
  }
}

///Button简单封装
class Button extends StatelessWidget {
  const Button(
      {Key? key,
      this.onPressed,
      required this.child,
      this.textStyle,
      this.backgroundColor,
      // this.foregroundColor,
      this.overlayColor,
      this.shadowColor,
      this.elevation,
      this.padding,
      this.minimumSize,
      this.side,
      this.shape})
      : super(key: key);
  final VoidCallback? onPressed;
  final Widget child;
  final TextStyle? textStyle; //字体
  final Color? backgroundColor; //背景色
  // final Color foregroundColor; //前景色（前景色为啥没效果）
  final Color? overlayColor; // 高亮色，按钮处于focused, hovered, or pressed时的颜色
  final Color? shadowColor; // 阴影颜色
  final double? elevation; // 阴影值
  final EdgeInsetsGeometry? padding; // padding
  final Size? minimumSize; //最小尺寸
  final BorderSide? side; //边框
  final OutlinedBorder? shape; //形状
  // final mouseCursor; //鼠标指针的光标进入或悬停在此按钮的[InkWell]上时。
  // final visualDensity; // 按钮布局的紧凑程度
  // final tapTargetSize; // 响应触摸的区域
  // final animationDuration; //[shape]和[elevation]的动画更改的持续时间。
  @override
  Widget build(BuildContext context) {
    return TextButton(
      onPressed: onPressed,
      child: child,
      style: ButtonStyle(
          textStyle: MaterialStateProperty.all(textStyle),
          elevation: MaterialStateProperty.all(elevation),
          padding: MaterialStateProperty.all(padding),
          side: MaterialStateProperty.all(side),
          shape: MaterialStateProperty.all(shape),
          backgroundColor: MaterialStateProperty.all(backgroundColor),
          minimumSize: MaterialStateProperty.all(minimumSize)),
    );
  }
}

///BaseTextStyle
class TStyle extends TextStyle {
  TStyle(
      {Color? color,
      double? fontSize,
      FontWeight? fontWeight,
      double? height,
      Color? backgroundColor,
      FontFamily? fontFamily})
      : super(
          color: color ?? const Color(0xff666666),
          fontSize: fontSize ?? 14,
          height: height,
          backgroundColor: backgroundColor,
          decoration: TextDecoration.none,
          fontWeight: fontWeight,
          fontFamily: _getFontFamily(fontFamily),
        );
}

String _getFontFamily(FontFamily? fontFamily) {
  switch (fontFamily) {
    case FontFamily.defaultFamily:
      return 'icons';
    case FontFamily.ybsFontFamily:
      return 'ysbth';
    default:
      return 'icons';
  }
}

enum FontFamily {
  /// 默认字体
  defaultFamily,

  /// 不知道啥字体
  ybsFontFamily,
}
